<?php

namespace api\user\controller;

class AdminUserController extends \Aaa\user\controller\AdminUserController {

    protected function init() {
        $this->baseField = [
            [
                'field' => 'id',
                'name' => 'ID',
            ],
            [
                'field' => 'user_pass',
                'name' => '密码',
            ],
            [
                'field' => 'avatar',
                'name' => '头像',
                'type' => 'image',
            ],
            [
                'field' => 'user_nickname',
                'name' => '昵称',
            ],
            [
                'field' => 'mobile',
                'name' => '手机',
            ],
            [
                'field' => 'money',
                'name' => '资金',
            ],
            [
                'field' => 'free_withdrawal_amount',
                'name' => '免费提现额度',
            ],
            [
                'field' => 'group_id',
                'name' => '级别组',
                'type' => 'select',
                'optionsSource' => [
                    'table' => 'user_group',
                    'nameField' => 'name',
                    'valueField' => 'id',
                ],
            ],
            [
                'field' => 'create_time',
                'name' => ' 注册时间',
                'type' => 'time',
            ],
            [
                'field' => 'last_login_time',
                'name' => ' 登录时间',
                'type' => 'time',
            ],
            [
                'field' => 'last_login_ip',
                'name' => '登录IP',
            ],
            [
                'field' => 'user_status',
                'name' => '状态',
                'type' => 'select',
                'options' => [
                    ['name' => '已拉黑', 'value' => 0],
                    ['name' => '正常', 'value' => 1],
                    ['name' => '未验证', 'value' => 2],
                ],
            ],
            [
                'field' => 'vbank',
                'name' => '实名状态',
                'type' => 'switch',
                'options' => ['通过', '未通过'],
            ],
            [
                'field' => 'name',
                'name' => '姓名',
            ],
            [
                'field' => 'alipay',
                'name' => ' 支付宝',
            ],
        ];
    }

    protected function beforeIndex() {
        $this->actionField = [
            'id',
            'avatar',
            'user_nickname',
            'mobile',
            'money',
            'free_withdrawal_amount',
            'group_id',
            'create_time',
            'last_login_time',
            'last_login_ip',
            'user_status',
            'vbank',
            'name',
            'alipay',
        ];
        $this->searchField = [
            'common' => [
                'id' => 'accurate',
                'user_nickname' => 'fuzzy',
                'mobile' => 'fuzzy',
                'group_id' => 'accurate',
                'last_login_ip' => 'fuzzy',
                'user_status' => 'accurate',
                'vbank' => 'accurate',
                'name' => 'fuzzy',
                'alipay' => 'fuzzy',
            ],
            'time' => ['create_time', 'last_login_time', ],
            'amount' => ['money'],
        ];
    }

    protected function beforeAdd() {
        $this->actionField = ['user_nickname', 'mobile', 'user_pass',];
    }

    protected function beforeEdit() {
        $this->actionField = [
            'avatar',
            'user_nickname',
            'mobile',
            'group_id',
            'vbank',
            'name',
            'alipay',
            'free_withdrawal_amount',
        ];
    }

    protected function beforeDeletePost() {
        if (is_array($this->paramId)) {
            $this->error('创始人用户不能删除', !in_array(1, $this->paramId));
        } else {
            $this->error('创始人用户不能删除', $this->paramId != 1);
        }
    }

}